<!-- views/sales/commission/components/CommissionFilter.vue -->
<template>
  <el-card class="filter-card" shadow="never">
    <el-form :model="queryParams" inline>
      <el-form-item label="提成日期">
        <el-date-picker
          v-model="queryParams.dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="YYYY-MM-DD"
          style="width: 220px"
        />
      </el-form-item>
      
      <el-form-item label="销售员">
        <el-select
          v-model="queryParams.salespersonId"
          clearable
          placeholder="选择销售员"
          style="width: 150px"
        >
          <el-option
            v-for="person in salespersons"
            :key="person.id"
            :label="person.name"
            :value="person.id"
          />
        </el-select>
      </el-form-item>
      
      <el-form-item label="状态">
        <el-select v-model="queryParams.status" clearable placeholder="全部状态" style="width: 120px">
          <el-option label="待审核" value="pending" />
          <el-option label="已审核" value="approved" />
          <el-option label="已发放" value="paid" />
        </el-select>
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" :icon="Search" @click="handleSearch">
          查询
        </el-button>
        <el-button :icon="Refresh" @click="handleReset">
          重置
        </el-button>
        <el-button 
          link
          :icon="SetUp" 
          @click="showAdvancedFilter = !showAdvancedFilter"
        >
          高级筛选
        </el-button>
      </el-form-item>
    </el-form>

    <!-- 高级筛选 -->
    <el-collapse-transition>
      <div v-show="showAdvancedFilter" class="advanced-filter">
        <el-divider content-position="left">高级筛选</el-divider>
        <el-form :model="queryParams" inline>
          <el-form-item label="订单金额">
            <el-input-number
              v-model="queryParams.minAmount"
              :min="0"
              placeholder="最小金额"
              style="width: 120px"
            />
            <span class="separator">-</span>
            <el-input-number
              v-model="queryParams.maxAmount"
              :min="0"
              placeholder="最大金额"
              style="width: 120px"
            />
          </el-form-item>
          
          <el-form-item label="提成金额">
            <el-input-number
              v-model="queryParams.minCommission"
              :min="0"
              placeholder="最小提成"
              style="width: 120px"
            />
            <span class="separator">-</span>
            <el-input-number
              v-model="queryParams.maxCommission"
              :min="0"
              placeholder="最大提成"
              style="width: 120px"
            />
          </el-form-item>
        </el-form>
      </div>
    </el-collapse-transition>
  </el-card>
</template>

<script setup lang="ts">
import { ref, defineProps, defineEmits } from 'vue'
import { Search, Refresh, SetUp } from '@element-plus/icons-vue'

const showAdvancedFilter = ref(false)

interface Salesperson {
  id: number
  name: string
}

interface QueryParams {
  dateRange: string[]
  salespersonId: string
  status: string
  minAmount: number | undefined
  maxAmount: number | undefined
  minCommission: number | undefined
  maxCommission: number | undefined
  page: number
  limit: number
}

const props = defineProps<{
  queryParams: QueryParams
  salespersons: Salesperson[]
}>()

const emit = defineEmits<{
  (e: 'search'): void
  (e: 'reset'): void
}>()

const handleSearch = () => {
  emit('search')
}

const handleReset = () => {
  emit('reset')
}
</script>

<style scoped>
.filter-card {
  margin-bottom: 20px;
}

.advanced-filter {
  margin-top: 16px;
}

.advanced-filter :deep(.el-divider) {
  margin: 16px 0;
}

.separator {
  margin: 0 8px;
  color: #c0c4cc;
}
</style>